package sdk.android.callrecorder.lv.adapter;

import java.util.ArrayList;

import sdk.android.callrecorder.R;
import sdk.android.callrecorder.data.RecordHistory;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class RecordHistoryListAdapter extends ArrayAdapter<RecordHistory>  {

	public RecordHistoryListAdapter(Context context, ArrayList<RecordHistory> items) {
		super(context, R.layout.list_row_record, items);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(getContext());
			convertView = inflater.inflate(R.layout.list_row_record, null);

			convertView.setTag(R.id.tv_file_name, convertView.findViewById(R.id.tv_file_name));
			convertView.setTag(R.id.tv_time, convertView.findViewById(R.id.tv_time));
		}

		RecordHistory data = getItem(position);

		convertView.setTag(data);

		((TextView) convertView.getTag(R.id.tv_time)).setCompoundDrawablesWithIntrinsicBounds(data.inout_flag == 0 ? R.drawable.contact : R.drawable.contact, 0, 0, 0);
		((TextView) convertView.getTag(R.id.tv_time)).setText(data.record_date);
		((TextView) convertView.getTag(R.id.tv_file_name)).setText(data.file_name);
		
		return convertView;
	}
}
